import request from '@/utils/request';
import type { FromUserType } from '@/pages/admin/UserManager/src/data';
import type { ResultType } from './type';

export type FindUserType = {
  userName?: string;
  _id?: string;
  email?: string;
  phone?: number;
  roleName?: string;
  startTime?: string;
  endTime?: string;
};

export async function createUser(params: FromUserType): Promise<ResultType> {
  return request('/api/createUser', {
    method: 'POST',
    data: params,
  });
}

export async function queryUser(params?: FindUserType): Promise<ResultType> {
  return request('/api/findUser', {
    method: 'GET',
    params,
  });
}

export async function findCurrent(params: { _id: string }): Promise<ResultType> {
  return request('/api/currentUser', {
    method: 'GET',
    params,
  });
}

export async function updateUser(params: FromUserType): Promise<ResultType> {
  return request('/api/updateUser', {
    method: 'POST',
    data: params,
  });
}

export async function removeUser(params: { userName: string }): Promise<ResultType> {
  return request('/api/removeUser', {
    method: 'POST',
    data: params,
  });
}

export async function queryNotices(): Promise<ResultType> {
  return request('/api/notices');
}

export async function uploadBase64(params: { img: string }): Promise<ResultType> {
  return request('/api/manage/base64/upload', {
    method: 'POST',
    data: params,
  });
}
